<?php
/**
 * Created by jinqiang on 2024/6/7 15:54.
 * Copyright (c) 2024, Your Company. All rights reserved.
 */


namespace App\Http\Controllers\Banshi;


use App\Http\Controllers\Controller;
use App\Http\Services\Banshi\PlanService;
use Illuminate\Http\Request;

class PlanController extends Controller
{
    public function list(Request $request, PlanService $planService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $res = $planService->search($param);
        return result($res);
    }

    public function status(Request $request, PlanService $planService)
    {
        $this->validate($request, [
            'id' => 'required',
            'status' => 'required'
        ]);
        $param = $request->all();
        $res = $planService->setStatus($param['id'], $param['status']);
        return $res['code'] === 0 ? success("更新成功") : error($res['msg'], $res);
    }

    public function save(Request $request, PlanService $planService)
    {
        $this->validate($request, [
            'data' => 'required',
        ]);
        $param = json_decode($request->data, true);
        $id = $param['id'] ?? "";
        $res = $planService->save($id, $param);
        return $res['code'] === 0 ? success("保存成功") : error($res['msg'], $res);
    }

    public function select(Request $request, PlanService $planService)
    {
        $this->validate($request, [
            'base_code_id' => 'required',
            'plan_id' => 'required'
        ]);
        $param = $request->all();
        $res = $planService->selectPlan($param['base_code_id'], $param['plan_id']);
        return result($res);
    }
}
